package com.study.multithreading.dateformat;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAccessor;
import java.util.ArrayList;
import java.util.Date;
import java.util.TimeZone;

/**
 * @author HBZ
 * @description
 * @date 2021/5/13 14:13
 */
public class DateUtilTest {
    public static class TestSimpleDateFormatThreadSafe extends Thread {
        @Override
        public void run() {
            while (true) {
                try {
                    this.join(1000);
                } catch (InterruptedException e1) {
                    e1.printStackTrace();
                }
                try {
                    System.out.println(this.getName() + ":" + DateUtil3ThreadLocal1.parse("2013-05-24 06:02:20"));
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }
        }
    }


    public static void main(String[] args) {
      /*  for(int i = 0; i < 3; i++){
            new TestSimpleDateFormatThreadSafe().start();
        }*/
        LocalDateTime now = LocalDateTime.now();
        System.out.println(now);

//自定义时区
        LocalDateTime now2 = LocalDateTime.now(ZoneId.of("Europe/Paris"));
        System.out.println(now2);//会以相应的时区显示日期
        System.out.println(LocalDate.now().toString());
        System.out.println(LocalDateTime.now().toString());
        System.out.println(LocalTime.now().toString());
        LocalDateTime of = LocalDateTime.of(2020, 11, 2, 2, 3,3);
        System.out.println(of.toLocalTime());
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        for (int i = 0; i < 1000; i++) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    TemporalAccessor parse = dateTimeFormatter.parse("2019-05-19 14:22:52");
                    LocalDateTime from = LocalDateTime.from(parse);
                    Instant second = from.toInstant(ZoneOffset.ofTotalSeconds(0));
                    System.out.println(second);
                }
            }).start();
        }
    }
}
